package com.newly.common.base.exception.handler;

import com.newly.common.base.entity.R;
import com.newly.common.base.exception.NewlyException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author gjm guan
 * @date 2021/8/19 15:50
 * @desc 处理NewlyException异常
 */
@RestControllerAdvice
@Slf4j
public class NewlyExceptionHandler {

    @ExceptionHandler(NewlyException.class)
    public R newlyExceptionHandler(NewlyException newlyException) {
        log.error("-----------------------------NewlyException begin-----------------------------");
        Integer code = newlyException.getCode();
        String msg = newlyException.getErrMsg();
        Object data = newlyException.getData();
        log.error("code = {} , msg = {}, data = {} ", code, msg, data);
        log.error("-----------------------------NewlyException after-----------------------------");
        return R.fail(code, data, msg);
    }
}
